package com.hk.card;

import java.util.ArrayList;

import javax.swing.ImageIcon;

public class CardCase {
	private static CardCase cardCase;
	private ArrayList<Card> cardList;
	private int count = 0;
	private int totalCard = 52;
	private String[] cardName = new String[] {"h", "d", "c", "s"};
	//
	private CardCase() {
		cardList = new ArrayList<Card>();
	}
	public static CardCase getCardCase() {
		if(cardCase==null) {	cardCase = new CardCase();		}
		return cardCase;
	}
	//set
	public void CardSet() {
		count = 0;
		cardList.clear();
		CardRandomSet();
	}
	//get
	public ArrayList<Card> getCardList() {
		return cardList;
	}
	public int getCardNum() {
		return cardList.get(count).getNumber();
	}
//	public Card getCard() {
//		return cardList.get(count++);
//	}
	public ImageIcon getCard() {
		return cardList.get(count++).getIcon();
	}
	//
	private void CardRandomSet() {
		while (true) {
			int tempI = makeRandomNum();
			String tempS = makeRandomName();
			if (!hasSame(tempI, tempS)) {
				cardList.add(new Card(tempS, tempI));
			}
			if (cardList.size()==totalCard) {
				break;
			}
		}
	}
	private boolean hasSame(int tempI, String tempS) {
		for (int i = 0; i < cardList.size(); i++) {
			if ((cardList.get(i).getNumber()==tempI) && (cardList.get(i).getName().equals(tempS))) {
				return true;
			}
		}
		return false;
	}
	private String makeRandomName() {
		int ran = (int)(Math.random() * 4);
		return cardName[ran];
	}
	private int makeRandomNum() {
		return (int)((Math.random() * 13) +1);
	}
}
